{extend name='admin@main'}

{block name="content"}
<form class="layui-form layui-card" onsubmit="return false;" action="{:request()->url()}" data-auto="true" method="post"
      autocomplete="off">
    <div class="layui-card-body">
        <div class="layui-form-item">
            <label class="layui-form-label">优惠券名称</label>
            <div class="layui-input-block label-required">
                <input name="name" value='{$vo.name|default=""}' required placeholder="请输入优惠券名称" class="layui-input">
                <!--{/if}-->
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">优惠券类型</label>
            <div class="layui-input-block label-required">
                <select class="layui-input-block label-required" name="type" id="type"  lay-filter="type">
                    {foreach $typeData as $type}
                    {if isset($vo.type) and $vo.type eq $type.id}
                    <option selected value="{$type.id}">{$type.name|default=''}</option>
                    {else}
                    <option value="{$type.id}">{$type.name|default=''}</option>
                    {/if}
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item type_1" style="display: none">
            <label class="layui-form-label">折扣</label>
            <div class="layui-inline ">
                <div class="layui-input-inline" style="width: 300px;">
                    <input type="text" name="discount_value" value='{$vo.discount_value|default=""}'  placeholder="满￥" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid">打折</div>
                <div class="layui-input-inline label-required" style="width: 300px;">
                    <input type="text" name="discount" value='{$vo.discount|default=""}' placeholder="" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">提示:如打85折输入85;&nbsp;&nbsp;9折输入<span style="color: red">90</span></div>
            </div>
        </div>
        <div class="layui-form-item type_2" style="display: none">
            <label class="layui-form-label">满减</label>
            <div class="layui-inline label-required">
                <div class="layui-input-inline" style="width: 300px;">
                    <input type="text" name="meet_value" value='{$vo.meet_value|default=""}'  placeholder="满￥" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid">立减</div>
                <div class="layui-input-inline" style="width: 300px;">
                    <input type="text" name="reduction" value='{$vo.reduction|default=""}' placeholder="￥" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item type_3" style="display: none">
            <label class="layui-form-label">立减</label>
            <div class="layui-input-inline label-required" style="width: 300px">
                <input name="amount" value='{$vo.amount|default=""}'  placeholder="请输入立减金额" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">优惠券数量</label>
            <div class="layui-input-inline label-required" style="width: 300px">
                <input name="count" type="number" value='{$vo.count|default=-1}' required placeholder="请输入优惠券数量"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">提示:请输入优惠券数量（-1 为不限制）</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">领取数量</label>
            <div class="layui-input-inline label-required" style="width: 300px">
                <input name="limit_count" type="number" value='{$vo.limit_count|default=1}' required placeholder="请输入领取数量"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">提示:请输入每个用户领取优惠券数量（-1 为不限制）</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">使用场景</label>
            <div class="layui-input-block label-required">
                <select class="layui-input-block label-required" name="use_type"  lay-filter="use_type" id="activity_type">
                    {foreach $useTypeData as $use}
                    {if isset($vo.use_type) and $vo.use_type eq $use.id}
                    <option selected value="{$use.id}">{$use.name|default=''}</option>
                    {else}
                    <option value="{$use.id}">{$use.name|default=''}</option>
                    {/if}
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item limit_cate_1" style="display: none">
            <label class="layui-form-label">活动类型</label>
            <div class="layui-input-block label-required">
                <select class="layui-input-block label-required" name="activity_type" >
                    {foreach $activityType as $activity}
                    {if isset($vo.activity_type) and $vo.activity_type eq $activity.id}
                    <option selected value="{$activity.id}">{$activity.name|default=''}</option>
                    {else}
                    <option value="{$activity.id}">{$activity.name|default=''}</option>
                    {/if}
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">关联产品</label>
            <div class="layui-input-inline label-required" style="width: 300px">
                <input name="product_id" type="text" value='{$vo.product_id|default="-1"}' required placeholder="请输入关联产品"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">提示:输入产品ID,如多个用逗号(,)隔开,如1,2,3;若无限制输入-1 &nbsp;&nbsp;&nbsp;
                <a href="/#/activity/index/index.html?spm=m-59-60-61" target="_blank">查看活动ID</a>&nbsp;
                <a href="/#/store/goods/index.html?spm=m-13-48-14" target="_blank">查看商品ID</a>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">使用时效</label>
            <div class="layui-input-block label-required">
                <select class="layui-input-block label-required" name="limit_use_type" id="limitData"  lay-filter="limitData">
                    {foreach $limitData as $limit}
                    {if isset($vo.type) and $vo.type eq $limit.id}
                    <option selected value="{$limit.id}">{$limit.name|default=''}</option>
                    {else}
                    <option value="{$limit.id}">{$limit.name|default=''}</option>
                    {/if}
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item limit_date_1" style="display: none">
            <label class="layui-form-label">开始使用日期</label>
            <div class="layui-input-block">
                <input data-date-one name="use_start_time" value="{$vo.use_start_time|default=''}" required
                       placeholder="开始使用日期" class="layui-input">
            </div>
            <label class="layui-form-label">过期日期</label>
            <div class="layui-input-block">
                <input data-date-one name="use_end_time" value="{$vo.use_end_time|default=''}" required
                       placeholder="请选择过期日期" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item limit_date_2" style="display: none">
            <label class="layui-form-label">有效天数</label>
            <div class="layui-input-inline label-required" style="width: 300px">
                <input name="limit_use_day" type="number" value='{$vo.limit_use_day|default=""}' required placeholder="请输入有效天数"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">提示:领取N天内有效</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">指定会员</label>
            <div class="layui-input-inline label-required" style="width: 600px">
                <input name="user_ids" type="text" value='{$vo.user_ids|default="-1"}' required placeholder="请输入指定会员open_id"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">提示:输入会员openid,如多个用逗号(,)隔开;若无限制输入-1 &nbsp;&nbsp;&nbsp;
                <a href="/admin.html#/store/member/index.html?spm=m-13-48-42" target="_blank">查看open_id</a>&nbsp;
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">指定跳转url</label>
            <div class="layui-input-inline" style="width: 600px">
                <input name="url" type="text" value='{$vo.url|default=""}'  placeholder="请输入指定领取后跳转url"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        <div class="layui-form-item">
            <h3 class="color-green"><sup class='color-red font-s14 absolute' style="margin-left:-10px">*</sup>优惠券详情</h3>
            <textarea name="desc">{$vo.desc|default=''|raw}</textarea>
        </div>
    </div>
    <div class="hr-line-dashed"></div>
    <div class="layui-form-item text-center">
        {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>
</form>

{/block}
{block name='script'}
<script>
    window.form.render();
    require(['ckeditor', 'angular',], function () {
            window.createEditor('[name="desc"]', {height: 500});
        }
    );
    $(".type_"+ $("#type").val()).show();
    form.on('select(type)', function(data){
        $(".type_"+ data.value).show();
        $("[class*='type_']").not(".type_"+ data.value).hide()
    });
    $(".limit_date_"+ $("#limitData").val()).show();
    form.on('select(limitData)', function(data){
        $(".limit_date_"+ data.value).show();
        $("[class*='limit_date_']").not(".limit_date_"+ data.value).hide()
    });
    $(".limit_cate_"+ $("#activity_type").val()).show();
    form.on('select(use_type)', function(data){
        $(".limit_cate_"+ data.value).show();
        $("[class*='limit_cate_']").not(".limit_cate_"+ data.value).hide()
    });
</script>
{/block}